/**
 * Copyright 2019-2021 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "comm_log.h"
#include "common/resource_def.h"

namespace fe {
const uint32_t TIMESTRING_MAXSIZE = 30;

const char *GetCurrentTime()
{
  static char timeString[TIMESTRING_MAXSIZE] = {'0'};
  return timeString;
}

struct funcStateInfo {
  bool isConfiged;
  bool isOpen;
};
using funcState = struct funcStateInfo;

class FuncSetting {
 private:
  funcState state[MAX_NUM];

 protected:
  FuncSetting()
  {
    for (int i = 0; i < MAX_NUM; i++) {
      state[i].isConfiged = false;
      state[i].isOpen = false;
    }
  }
  ~FuncSetting() {}

 public:
  static FuncSetting *Instance();
  ccStatus_t SetFuncState(funcParamType_t type, bool isOpen);
  bool GetFuncState(funcParamType_t type);
};

FuncSetting *FuncSetting::Instance()
{
  static FuncSetting instance;
  return &instance;
}

ccStatus_t FuncSetting::SetFuncState(funcParamType_t type, bool isOpen)
{
  if (type < MAX_NUM) {
    state[type].isConfiged = true;
    state[type].isOpen = isOpen;
    return CC_STATUS_SUCCESS;
  } else {
    CM_LOGE("SetFuncState type[%d] is invilid!", type);
    return CC_STATUS_BAD_PARAM;
  }
}

bool FuncSetting::GetFuncState(funcParamType_t type)
{
  if (type < MAX_NUM) {
    if (state[type].isConfiged)
    {
      return state[type].isOpen;
    }
  }
  return false;
}

ccStatus_t setFuncState(funcParamType_t type, bool isOpen)
{
  return FuncSetting::Instance()->SetFuncState(type, isOpen);
}

bool getFuncState(funcParamType_t type)
{
  return FuncSetting::Instance()->GetFuncState(type);
}

}
